import {takeEvery, put} from 'redux-saga/effects'
import {get_products, get_products_success} from '../actions/products'
import { API } from '../../config'
import axios from 'axios'

function* handleProduct (action) {
	let {data} = yield axios.get(`${API}/products`,{
		params: action.payload
	})
	yield put(
		get_products_success({
			sortBy: action.payload.sortBy,
			products: data
		})
	)
}

export default function* productsSaga () {
	yield takeEvery(get_products, handleProduct)
}